<?php
class Negotiation extends AppModel {
	var $name = 'Negotiation';
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Product' => array(
			'className' => 'Product',
			'foreignKey' => 'product_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
            'User' => array(
			'className' => 'User',
			'foreignKey' => 'seller_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
            'Buyer' => array(
			'className' => 'User',
			'foreignKey' => 'buyer_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

        function checkNegotiasion($buyerId, $sellerId, $proId){
            $this->recursive=-1;
            $negotiations=$this->find('first', array('conditions'=>array('Negotiation.buyer_id'=>$buyerId, 'Negotiation.seller_id'=>$sellerId, 'Negotiation.status'=>'Accepted', 'Negotiation.product_id'=>$proId )));
            if(count($negotiations)==0){
                return FALSE;
            }
            return $negotiations;
        }
}
?>